package com.zzyl.job;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import oshi.jna.platform.mac.SystemB;

import java.util.HashMap;
import java.util.Map;

public class WXopenid {
    public static void main(String[] args) {

        String OPENID_URL = "https://api.weixin.qq.com/sns/jscode2session";

        Map<String, Object> map = new HashMap<>();
        map.put("appid","wx792a8c42b620ec72");
        map.put("secret","4365ef6e897298e7eb1890b1ff1c69a5");
        map.put("js_code","0d3z0Y000L8Z9V1mtu30051Y4z2z0Y0R");
        map.put("grant_type","authorization_code");


        HttpResponse response = HttpUtil.createRequest(Method.GET,OPENID_URL )
//.body()
                .form(map).execute();
        if (response.isOk()){
            String body = response.body();
            JSONObject jsonObject = JSONUtil.parseObj(body);
            String openid = jsonObject.getStr("openid");
            System.out.println(openid);
           /* String openid = JSONUtil.parseObj(response.body()).getStr("openid");
            System.out.println(openid);*/

        }

    }
}
